
from rest_framework import serializers
from apps.common.base.serializers import BaseSerializer
from apps.system.dict.models import *

class DictBaseSerializer(BaseSerializer):

    class Meta:
        model = Dict
        fields = "__all__"

class DictModelSerializer(BaseSerializer):

    dictTypeModel = serializers.SerializerMethodField()
    def get_dictTypeModel(self, obj):
        if obj.dictType:
            return {'id': obj.dictType.id, 'name': obj.dictType.name, 'key': obj.dictType.key}
        return {}

    class Meta:
        model = Dict
        fields = "__all__"

class DictFormSerializer(BaseSerializer):

    class Meta:
        model = Dict
        fields = ['id', 'value', 'label']